#ifndef CHARACTER_H
#define CHARACTER_H

#include <QMap>
#include <QVector>
#include "GameObject.h"

//用于实现人物动画与移动的基本逻辑
class Character : public GameObject
{
public:
    // 方向枚举
    enum Direction { DIR_UP, DIR_DOWN, DIR_LEFT, DIR_RIGHT };

    explicit Character(QObject *parent = nullptr);

    // 动画控制
    void setAnimationFrames(Direction dir, const QVector<QPixmap> &frames);
    void setCurrentDirection(Direction dir, bool is_resetFrames = true);

    // 属性设置
    void setSpeed(float speed) { m_speed = speed; }
    float speed() const { return m_speed; }
    Direction currentDirection() const { return m_currentDirection; }

    // GameObject接口实现
    void update(float deltaTime) override;

    // 基础移动方法 (无逻辑判断)
    void move(float dx, float dy);

    //QString type() const override { return "Character"; }
protected:
    // 更新动画
    void updateAnimation(float deltaTime);

    // 初始化碰撞形状（在图像设置后调用）
    virtual void initializeCollisionShape();

    // 动画状态
    Direction m_currentDirection = DIR_DOWN;
    QMap<Direction, QVector<QPixmap>> m_animations;
    int m_currentFrame = 0;
    float m_frameTimer = 0.0f;
    const float FRAME_DURATION = 0.1f; // 每帧持续时间

    // 移动属性
    float m_speed = 120.0f;
};

#endif // CHARACTER_H
